package menu;

import java.awt.Font;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import font.GLFont;

public class MainMenu implements IMenu{
	private MenuItem newGame;
	private MenuItem exit;
	
	private GLFont font;
	
	private int result;
	
	@Override
	public void initialize(World world, FrameBuffer buffer){
		result = 0;
		
		//create font
		font = new GLFont(new Font("Arial", Font.BOLD, 30));
		
		//init menu items
		newGame = new MenuItem(world, buffer, font);
		newGame.setPosition(600, 70);
		newGame.setText("NEW GAME");
		newGame.initialize();
		
		newGame.addClickListener(new ClickEventHandler() {
			
			@Override
			public void onClick() {
				result = 1;
			}
		});
		
		exit = new MenuItem(world, buffer, font);
		exit.setPosition(600, 130);
		exit.setText("EXIT");
		exit.initialize();
		
		exit.addClickListener(new ClickEventHandler() {
			
			@Override
			public void onClick() {
				result = 2;
				
			}
		});
	}
	
	@Override
	public void update(World world, FrameBuffer buffer){
		buffer.blit(TextureManager.getInstance().getTexture("background"), 0, 0, 0, 0, 800, 600, true);
		newGame.update();
		exit.update();
	}
	
	public void dispose(){
		newGame.dispose();
		exit.dispose();
	}
	
	public int getResult(){
		int r = result;
		result = 0;
		return r;
	}
}
